package development.game;

import java.util.Hashtable;

import javax.microedition.lcdui.Graphics;

import development.Global;
import development.bean.Game;

import state.Alert;
import state.GameForm;
import state.GameGlobal;
import state.socket.DataPackage;
import state.socket.DataReceiveListener;

public class FrmBaCay extends GameForm implements DataReceiveListener {
  private static final int READY_IN_GAME_REQUEST = 3001;
  
  private static final int START_TO_PLAY_RESPONSE = 4001;
  
  public void init(Hashtable parameters) {
    long timeReady = System.currentTimeMillis();
    DataPackage dataPackage = Game.createGamePackage(READY_IN_GAME_REQUEST);
    dataPackage.putLong(timeReady);
    Global.gameActionClient.write(dataPackage);
  }
  
  public void alertEventPerform(int alertType, int eventType, int alertId) {
  }

  public void draw(Graphics g) {
  }

  public void onConnectDone() {
  }

  public void onConnectFail() {
  }

  public void onDisconnect() {
  }

  public void onRecieveData(DataPackage dataPackage) {
    int header = dataPackage.getHeader();
    switch (header) {
    case START_TO_PLAY_RESPONSE:
      String messageFromServer = dataPackage.nextString();
      GameGlobal.alert.showAlert(this, Alert.OK_TYPE, messageFromServer);
      break;
    }
    
  }
  
  protected void destroy() {
  }
}
